import { getUserService, loginService, logoutService, updateUserService } from "@/services/admin/auth";
import { captchaService } from "@/services/admin/auth";
import express from "express";

const router = express.Router();

router.post("/login", (req, res) => {
    /*
        #swagger.tags = ['管理端身份认证']
        #swagger.path = '/admin-api/auth/login'
        #swagger.description = '用户登录'
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        required: ['username', 'password', 'captcha'],
                        properties: {
                            username: { description: '用户名', type: 'string' },
                            password: { description: '密码', type: 'string' },
                            captcha: { description: '验证码', type: 'string' }
                        }
                    }
                }
            }
        }
    */
    loginService(req, res);
});

router.post("/logout", (req, res) => {
    /*
        #swagger.tags = ['管理端身份认证']
        #swagger.path = '/admin-api/auth/logout'
        #swagger.description = '用户登出'
    */
    logoutService(req, res);
});

router.get("/captcha", (req, res) => {
    /*
        #swagger.tags = ['管理端身份认证']
        #swagger.path = '/admin-api/auth/captcha'
        #swagger.description = '获取验证码'
    */
    captchaService(req, res);
});

router.get("/user", (req, res) => {
    /*
        #swagger.tags = ['管理端身份认证']
        #swagger.path = '/admin-api/auth/user'
        #swagger.description = '获取用户信息'
        #swagger.security = [{"bearerAuth": []}]
    */
    getUserService(req, res);
});

router.post("/updateUser", (req, res) => {
    /*
        #swagger.tags = ['管理端身份认证']
        #swagger.path = '/admin-api/auth/updateUser'
        #swagger.description = '更新用户信息'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        required: ["_id"],
                        properties: {
                            _id: { description: '用户ID', type: 'string' },
                            username: { description: '用户名', type: 'string' },
                            email: { description: '邮箱', type: 'string' },
                            roles: { description: '角色', type: 'array', items: { type: 'string' } },
                            status: { description: '状态', type: 'boolean' },
                            password: { description: '密码', type: 'string' },
                            nickname: { description: '昵称', type: 'string' },
                            avatar: { description: '头像', type: 'string' },
                            remark: { description: '备注', type: 'string' }
                        }
                    }
                }
            }
        }
    */
    updateUserService(req, res);
});

export default router;
